import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader'
/**
 * @description 获取dom长宽
 * @param domId {string} 容器id
 * @returns {{width: number, height: number}}
 */
export function getWH(domId) {
  const width = document.getElementById(domId).offsetWidth
  const height = document.getElementById(domId).offsetHeight
  return {
    width,
    height
  }
}

/**
 * @description 加载模型
 * @param url 地址
 * @returns {Promise<unknown>}
 */
export function loadObj(url) {
  const loaderObj = new OBJLoader()
  return new Promise((resolve) => {
    loaderObj.load(url, (object) => {
      resolve(object)
    })
  })
}

/**
 *  加载图片
 * @param src
 * @returns {Promise<unknown>}
 */
export function loadImage(src) {
  return new Promise((resolve, reject) => {
    const img = document.createElement('img')
    img.onload = function() {
      resolve(img)
    }
    img.onerror = function() {
      reject('图片加载失败')
    }
    img.src = src
  })
}
